package com.eqdd.yiqidian.ui.gongneng.car;

import android.databinding.DataBindingUtil;
import android.os.Bundle;
import android.support.v7.widget.RecyclerView;
import android.view.View;

import com.eqdd.yiqidian.R;
import com.eqdd.yiqidian.RecyclerViewCustom;
import com.eqdd.yiqidian.base.AppConstent;
import com.eqdd.yiqidian.base.Config;
import com.eqdd.yiqidian.bean.rebuild.CarInfoBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditEnterBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditHintBean;
import com.eqdd.yiqidian.bean.rebuild.slimedit.SlimEditTimeBean;
import com.eqdd.yiqidian.http.DialogCallBack;
import com.eqdd.yiqidian.http.HttpConfig;
import com.eqdd.yiqidian.http.HttpResult;
import com.eqdd.yiqidian.ui.base.SlimBaseMultiEditActivity;
import com.eqdd.yiqidian.ui.select.RichTextResult;
import com.eqdd.yiqidian.ui.select.SelectRichTextActivity;
import com.eqdd.yiqidian.ui.select.ShowRichTextActivity;
import com.eqdd.yiqidian.utils.PicUtil;
import com.eqdd.yiqidian.utils.ToastUtil;
import com.luck.picture.lib.entity.LocalMedia;
import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;

import java.util.ArrayList;
import java.util.List;


/**
 * @author吕志豪 .
 * @date 17-11-21  下午3:17.
 * Github :https://github.com/lvzhihao100
 * E-Mail：1030753080@qq.com
 * 简书 :http://www.jianshu.com/u/6e525b929aac
 */

public class CarInfoActivity extends SlimBaseMultiEditActivity {

    private RecyclerViewCustom dataBinding;
    private CarInfoBean items;

    @Override
    public void initBinding() {
        isRead = false;
        isSave = false;
        dataBinding = DataBindingUtil.setContentView(this, R.layout.activity_recyclerview);
        initTopTitleBar(View.VISIBLE, "车辆详情");
    }

    @Override
    protected RecyclerView initRecyclerView() {
        return dataBinding.recyclerView;
    }

    @Override
    public void itemClick(int p) {
        switch (slimAdapterEx.getDataItem(p).getPosition()) {
            case 10:
                Bundle bundle = new Bundle();
                bundle.putString(Config.TITLE, "备注");
                RichTextResult richTextResult = new RichTextResult();
                richTextResult.setContent(items.getRemark());
                ArrayList<LocalMedia> localMedia = new ArrayList<>();
                for (String s : items.getPicAddr()) {
                    localMedia.add(PicUtil.localMedia(s));
                }
                richTextResult.setSelectMedia(localMedia);
                bundle.putSerializable(Config.RICH_TEXT_RESULT, richTextResult);
                startActivityForResult(ShowRichTextActivity.class, bundle, Config.SELECT_RICH_TEXT);
                break;
        }
    }

    @Override
    protected void setEditBeans() {

    }

    @Override
    protected void loadNetData() {
        int id = getIntent().getIntExtra(Config.ID, -1);
        OkGo.<HttpResult<CarInfoBean>>post(HttpConfig.BASE_URL + HttpConfig.CAR_INFO)
                .params("userGuid", AppConstent.user.getGuid())
                .params("comid", AppConstent.user.getCompanyId())
                .params("vehicleId", id)
                .execute(new DialogCallBack<HttpResult<CarInfoBean>>(CarInfoActivity.this) {
                    @Override
                    public void onSuccess(Response<HttpResult<CarInfoBean>> response) {
                        HttpResult<CarInfoBean> httpResult = response.body();
                        ToastUtil.showShort(httpResult.getMsg());
                        if (httpResult.getStatus() == 200) {
                            items = httpResult.getItems();
                            datas.add(new SlimEditHintBean("车牌号码", items.getPlateNumber(), 0));
                            datas.add(new SlimEditHintBean("车辆类型", items.getVehicleType(), 1));
                            datas.add(new SlimEditHintBean("座位数(除司机)", items.getSeats() + "", 2));
                            datas.add(new SlimEditHintBean("颜色", items.getColor(), 3));
                            datas.add(new SlimEditHintBean("车辆识别号", items.getVIN(), 4));
                            datas.add(new SlimEditHintBean("发动机号码", items.getEngineCode(), 5));
                            datas.add(new SlimEditHintBean("购买日期", items.getPurchaseDate(), 6));
                            datas.add(new SlimEditHintBean("购买价格", items.getPurchasePrice() + "", 7));
                            datas.add(new SlimEditHintBean("保险到期时间", items.getInsuranceEndDate(), 8));
                            datas.add(new SlimEditHintBean("年检日期", items.getAnnInspectDate(), 9));
                            datas.add(new SlimEditEnterBean("备注", items.getRemark(), 10, true, "请输入"));
                            slimAdapterEx.notifyItemRangeInserted(0, datas.size());
                        }
                    }
                });
    }

    @Override
    protected void onTimeClick(int position) {

    }
}
